<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/4/1
 * Time: 下午3:38
 */

namespace app\index\controller;


use app\index\model\News;
use app\index\model\SubCategory;
use app\index\service\NewsService;
use think\Controller;
use think\Request;

class Consult extends BaseController
{
    public function index(){
        $rec_news_list = NewsService::getIndexRecNewsList(4);
        $this->assign("rec_news_list",$rec_news_list);
        $hot_news_list = NewsService::getHotNewsList(4);
        $this->assign("hot_news_list",$hot_news_list);
        $one_news = NewsService::getHotNewsList(1);
        $one_category_news = NewsService::getSubCategorysByNews(1);
        $category_news_list = NewsService::getSubCategorysByNews(3);
        $year = date('Y')."年";
        $this->assign("year",$year);
        $this->assign("one_news",$one_news);
        $this->assign("one_category_news",$one_category_news);
        $this->assign("category_news_list",$category_news_list);
        return $this->fetch("index");
    }
    
    public function constList($id, $page){
        if($id == null){
            $id = 0;
        }
        if($page == null){
            $page = 1;
        }
        if($page != 1){
            $pagetext = '第'.$page.'页';
        }else{
            $pagetext = '';
        }
        $news_list = News::getList($page);
        $last_news = News::getRecestOne();
        $create_time = str_replace('+00:00', 'T', gmdate('c', strtotime($last_news['create_time'])));
        $create_time =  substr($create_time,0,strlen($create_time)-1);
        $this->assign("news_list",$news_list);
        $this->assign("create_time",$create_time);
        $subcategory_name = SubCategory::getCategoryNameById($id);
        $year = date('Y')."年";
        $this->assign("year",$year);

        return $this->fetch("list", ["id"=>$id,"subcategory_name"=>$subcategory_name,"year"=>$year,"page"=>$page,"pagetext"=>$pagetext]);
    }
    
    public function constDetail($id){
    	if($id == null){
            $id = 0;
        }
        $news_detail = NewsService::getNewsDetail($id);
        $year = date('Y')."年";
        $this->assign("year",$year);
        $this->assign("news_detail",$news_detail);
        $seo = News::getSeoInfoByID($id);
        $title = $seo['title'];
        $desc = $seo['desc'];
        return $this->fetch("detail",  ["id"=>$id,"title"=>$title,"desc"=>$desc]);
    }
    
}